package com.hd.abc.books.servlet.serivletimpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hd.abc.books.common.ResponseResult;
import com.hd.abc.books.common.ResultTable;
import com.hd.abc.books.dao.booksdao;
import com.hd.abc.books.entity.book;
import com.hd.abc.books.servlet.ser;
import org.apache.ibatis.annotations.ResultType;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class serIMPL implements ser {
    @Resource
    private booksdao dao;

    @Override
    public ResultTable getdata(int page, int limit, String bookname, double a, double b) {
        QueryWrapper que=new QueryWrapper ();
        if (bookname!=null){
            que.like ("bookname", bookname);
        }
        if (b!=0){
            que.le ("bookprice",b);
        }
        if(a!=0){
            que.ge ("bookprice",a);
        }
        PageHelper.startPage (page,limit);
        List<book> books = dao.selectList (que);
        PageInfo dataall=new PageInfo (books);
        return new ResultTable (0,"",(int)dataall.getTotal (),dataall.getList ());
    }

    @Override
    public ResponseResult del(int id) {
        dao.deldata(id);
        return  ResponseResult.getSuccess ();

    }

    @Override
    public ResponseResult adddata(book book) {
        int i=dao.adddata(book);
        return ResponseResult.getSuccess ();
    }
}
